package com.xiaoxu.bbs.common;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用的返回结果类
 * @param <T>
 */
@Data
public class ReturnResults<T> {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> ReturnResults<T> success(T object) {
        ReturnResults<T> rr = new ReturnResults<>();
        rr.data = object;
        rr.code = 1;
        return rr;
    }

    public static <T> ReturnResults error(String msg) {
        ReturnResults rr = new ReturnResults();
        rr.msg = msg;
        rr.code = 0;
        return rr;
    }

    public ReturnResults<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}
